<html>
<head><meta charset="utf-8"><title>doubly-indirect recievers · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html">doubly-indirect recievers</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212419175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212419175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212419175">(Oct 06 2020 at 12:23)</a>:</h4>
<p>It appears that doubly-indirect recievers (like <code>self: &amp;Arc&lt;Self&gt;</code>) are stable, but are not object safe. I've tried to trace the history and tbh I'm quite confused how we got into this state. The stabilization report originally added doubly indirect pointers, then removed them, then there was discussion of adding them again but it never really concluded. The stabilization report suggests that they would have been object safe as well. <a href="https://github.com/rust-lang/rust/issues/55786">https://github.com/rust-lang/rust/issues/55786</a></p>



<a name="212419232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212419232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212419232">(Oct 06 2020 at 12:24)</a>:</h4>
<p>Does anyone know why doubly-indirect recievers are not object safe?</p>



<a name="212419551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212419551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212419551">(Oct 06 2020 at 12:27)</a>:</h4>
<p>I found the more recent issue: <a href="https://github.com/rust-lang/rust/issues/55786">https://github.com/rust-lang/rust/issues/55786</a></p>



<a name="212419685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212419685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212419685">(Oct 06 2020 at 12:28)</a>:</h4>
<p>there's no discussion of why they are not object safe or whether they ever can be, that's what I'd like to know</p>



<a name="212420132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212420132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212420132">(Oct 06 2020 at 12:32)</a>:</h4>
<p>and an issue in which Ralf and I had the same question, with no answer: <a href="https://github.com/rust-lang/rust/issues/64351">https://github.com/rust-lang/rust/issues/64351</a></p>



<a name="212420392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212420392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212420392">(Oct 06 2020 at 12:34)</a>:</h4>
<p>The way I see it, a doubly indirect receiver can be implemented when hand-rolling your own VTable and own <code>ArcDynObj</code> wrapper (can submit a playground with it if anyone is interested). So I personally fail to see why the compiler shouldn't be able to achieve this with its own auto-implemented stuff.</p>



<a name="212420683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212420683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212420683">(Oct 06 2020 at 12:37)</a>:</h4>
<p>(i'd be interested in seeing this playground, but not because it's hard to believe or anything, just because i remember implementing something similar in the past and getting lost on a couple points)</p>



<a name="212420838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212420838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212420838">(Oct 06 2020 at 12:38)</a>:</h4>
<p><span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span> Exactly; it's how we convert <code>Arc&lt;dyn Wake&gt;</code> to <code>Waker</code>.</p>



<a name="212421102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212421102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212421102">(Oct 06 2020 at 12:40)</a>:</h4>
<p>I thought of the waker (it looks like one of the ugly / <code>unsafe</code> things in the std library public API, because of this very reason), but I think that in that instance we may be "cheating" by flattening the indirection through <code>Arc::{from,into}_raw</code>. I do think we wouldn't even need to "cheat" (so as to be more general _w.r.t._ the kind of smart pointer being used)</p>



<a name="212421448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212421448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212421448">(Oct 06 2020 at 12:43)</a>:</h4>
<p>ah right, the function in the vtable isn't even passed a double pointer for <code>wake_by_ref</code></p>



<a name="212426496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212426496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212426496">(Oct 06 2020 at 13:24)</a>:</h4>
<p><span class="user-mention" data-user-id="209168">@Thom Chiovoloni</span> <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=f50860c473c5806691b49c091790ff6b">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=f50860c473c5806691b49c091790ff6b</a><br>
The most notable thing, however, is that I have had to rely on the layout of <code>TraitObject</code>; that is, that the first field of the struct is the slim pointer. So in that regard it isn't as trivial as I had anticipated, since, AFAIK, that is not a guarantee that Rust wants to make yet, and it feels to me that this cannot be done otherwise</p>



<a name="212426556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212426556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212426556">(Oct 06 2020 at 13:25)</a>:</h4>
<p>okay, i think that was the same thing i hit in the past. thanks. (i do agree that the issue is irrelevant for this context)</p>



<a name="212427055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212427055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212427055">(Oct 06 2020 at 13:29)</a>:</h4>
<p>Also, I realize too that this makes so that the non-doubly indirect method calls need to rely on layout and offsetting the <code>*const ArcInner&lt;ty::Erased&gt;</code> pointer to get back a <code>*const ty::Erased</code> it can feed to such methods. I don't know if that is how this is implemented as of today</p>



<a name="212603207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/doubly-indirect%20recievers/near/212603207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/doubly-indirect.20recievers.html#212603207">(Oct 07 2020 at 18:56)</a>:</h4>
<p><span class="user-mention" data-user-id="256759">@boats</span> I'm not sure of any reason off the top of my head</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>